home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Garbo
/
Garbo.cdr
/
mac
/
hypercrd
/
xcmd
/
dxcmds34.sit
/
Dartmouth XCMD's 3.4.3
/
card_8751.txt
< prev
next >
Wrap
Text File
|
1990-04-17
|
14KB
|
428 lines
-- card: 8751 from stack: in.3
-- bmap block id: 14237
-- flags: 4000
-- background id: 8327
-- name: C Utilities
-- part 5 (field)
-- low flags: 01
-- high flags: 2007
-- rect: left=18 top=32 right=290 bottom=486
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 10
-- style flags: 0
-- line height: 13
-- part name: Documentation
-- part 6 (button)
-- low flags: 00
-- high flags: 8003
-- rect: left=299 top=298 right=320 bottom=438
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: Show C Source
----- HyperTalk script -----
on mouseUp
get the visible of card field "source"
set the visible of card field "source" to not it
if it is false then
set the name of me to "Hide C Source"
else
set the name of me to "Show C Source"
end if
end mouseUp
-- part 7 (field)
-- low flags: 81
-- high flags: 0007
-- rect: left=18 top=31 right=291 bottom=486
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 10
-- style flags: 0
-- line height: 13
-- part name: Source
-- part 11 (field)
-- low flags: 81
-- high flags: 0007
-- rect: left=18 top=32 right=285 bottom=481
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: got
-- part contents for card part 5
----- text -----
C Utilities 1.0d4
Roger Brown
This is a collection of various C functions that are useful when creating XFCN's.
They are written in THINK CΓäó.
New this version:
ΓÇó GetCardRect: gets the screen rectangle of the card window. Works with
SuperCard.
ΓÇó ShowString: a debugging tool that lets you display a string in an answer dialog.
ΓÇó GetHCWord: gets a specified word from a HyperCard container.
Previously released:
ΓÇó Number of HyperCard Items : int NumHCitems(char *source)
Given a pointer to a source of HyperCard formatted items (comma delimited), return
the number of items in it.
ΓÇó Get HyperCard Item : GetHCItem(char *inStr, int i, char *outStr)
Given a HyperCard item list (comma delimited) in string inStr, get item i and return it
as a string in outStr.
ΓÇó Number of HyperCard Lines : int NumHCLines(char *source)
Given a pointer to a source of HyperCard formatted lines, such as a field, return the
number of lines in it.
ΓÇó Get HyperCard Line : GetHCLine(int line, char *source, char *dest)
Given a pointer to a source of lines (like a field), extract the requested line and return
it in string dest.
ΓÇó Get HyperCard Expression : GetHCExpression(char *inStr, char *outStr)
Given a HyperCard expression in inString, return its value in outStr.
ΓÇó String Contains : StrContains(char *target, char *test)
Given string test, return TRUE if it contains the string target.
ΓÇó Get HyperCard Card WindowRectangle : GetCardRect(Rect *itsRect)
Get the rectangle of HyperCard's card window.
ΓÇó Build a return result : ResultIs(XCmdBlockPtr paramPtr, char *theResult)
Given a C formatted string, build a return result structure for the given parameter
block.
ΓÇó GetHCRectangle: GetHCRectangle(str,aRect)
Given a HyperCard rectangle specification in a string, return a QuickDraw rectangle.
-- part contents for card part 7
----- text -----
/* C Utilities 1.0a4.c */
/* version 1.0a4 9/14/89 */
/* Roger Brown, Dartmouth Courseware Development Group 7/7/88 */
/* HyperCard XCMD support library */
#include "HyperXCmd.h"
/* change a string to all upper case */
ucase(s)
char *s;
{
int i;
char c;
for (i=0;i<strlen(s);i++) {
s[i] = toupper(s[i]);
}
}
/* get a specified word from a HyperCard container */
GetHCWord(inStr,i,outStr)
char *inStr,*outStr;
int i;
{
int c; /* character pointer */
int len; /* length to scan */
int count; /* count of items found */
int j; /* item byte count */
Str255 temp; /* collect item here, hope its < 255 */
count = j = 0; /* initialize */
len = strlen(inStr); /* go this far, max */
for (c=0;c<len;c++) {
if (inStr[c]==' ') { /* at an word boundary */
count = count + 1; /* bump counter */
if (count==i) break; /* if this is it, stop scanning */
j = 0; /* else start on the next item */
}
else {
temp[j] = inStr[c]; /* collect characters to return */
j++; /* go to next */
if (j==255) { /* sorry, too big to store */
strcpy(temp,"Error: word > 255 characters.");
return;
}
if (c==(len-1)) { /* last word, no space */
count = count+1;
break;
}
}
}
if (count < i) strcpy(outStr,"Error: word out of range"); /* no word there */
else {
temp[j] = 0; /* make it a C string */
strcpy(outStr,temp); /* move to output string */
}
return;
}
/* Get the number of HyperCard comma delimited items in string s. */
int NumHCItems(s)
char *s;
{
int c; /* character pointer */
int len; /* length of string */
int count; /* count of items found */
int j; /* item byte counter */
count = j = 0; /* initialize */
len = strlen(s); /* will look this far */
for (c=0;c<len;c++) { /* scan all characters */
if (s[c]==',') { /* found end of an item */
count = count + 1; /* bump item found counter */
j = 0; /* reset item scan counter */
}
else {
j++; /* bump item byte counter */
if (c==(len-1)) { /* last item, no comma */
count = count+1; /* this one counts, too */
break;
}
}
}
return count;
}
/* Get HyperCard comma delimited item i from item list string inStr. Return it in outStr */
/* item must be smaller than 255 characters */
GetHCItem(inStr,i,outStr)
char *inStr,*outStr;
int i;
{
int c; /* character pointer */
int len; /* length to scan */
int count; /* count of items found */
int j; /* item byte count */
Str255 temp; /* collect item here, hope its < 255 */
count = j = 0; /* initialize */
len = strlen(inStr); /* go this far, max */
for (c=0;c<len;c++) {
if (inStr[c]==',') { /* at an item boundary */
count = count + 1; /* bump counter */
if (count==i) break; /* if this is it, stop scanning */
j = 0; /* else start on the next item */
}
else {
temp[j] = inStr[c]; /* collect characters to return */
j++; /* go to next */
if (j==255) { /* sorry, too big to store */
strcpy(temp,"Error: Item > 255 characters.");
return;
}
if (c==(len-1)) { /* last item, no comma */
count = count+1;
break;
}
}
}
if (count < i) strcpy(outStr,"Error: item out of range"); /* no item there */
else {
temp[j] = 0; /* make it a C string */
strcpy(outStr,temp); /* move to output string */
}
return;
}
/* how many HyperCard lines in string source */
NumHCLines(source)
char *source;
{
int c; /* character counter */
int l; /* line counter */
int len;
len = strlen(source);
l = 0;
for (c=0;c<len;c++) { /* scan to desired line */
if (source[c]==13) l++;
}
if (source[c-1]!=13) l++; /* last line might not have CR */
return l;
}
/* get HyperCard line from source and return in dest */
GetHCLine(line,source,dest)
int line;
char *source,*dest;
{
int i; /* char counter before line */
int j; /* char cou,tner after line */
int c; /* line counter */
int len; /* length of source */
len = strlen(source); /* go this far, max */
c = 1; /* initialize */
i = 0;
while (c<line) { /* cycle to desired line */
if (source[i]==13) c++; /* bump line count */
i++;
if (i>len) { /* out of range */
strcpy(dest,"Error: Line out of range.");
return;
}
}
c = 0; /* at line, start transfer */
for (j=i;j<len;j++) {
*(dest+c) = source[j];
if (source[j]==13) break; /* line ended */
c++;
}
*(dest+c) = (char)0; /* make into a C string */
}
/* Given a HyperCard expression in inStr, return its value in outStr */
GetHCExpression(paramPtr,inStr,outStr)
XCmdBlockPtr paramPtr;
char *inStr;
Str255 *outStr;
{
Handle theResult; /* handle to the final result */
long len; /* length needed */
#ifdef XCMD
strcpy(outStr,inStr); /* cheat a little, use outStr as an intermediate */
CtoPstr((char *)outStr); /* make it a P string */
theResult = EvalExpr(paramPtr,outStr); /* get its value from HC */
len = GetHandleSize(theResult); /* how long is it? */
BlockMove(*theResult,outStr,len); /* move the result into outStr */
DisposHandle(theResult); /* tidy up */
#endif
}
/* Return true if target string contains test string. Match is not case sensitive. */
char StrContains(target,test)
char *target,*test;
{
char ok;
int i;
char *j,*k;
int targetLen,testLen;
char go;
targetLen = strlen(target); /* scan this far, max */
testLen = strlen(test); /* look for this many matches */
for (i=0;i<targetLen;i++) {
j = target+i;
k = test;
while (toupper(*j)==toupper(*k)) { /* loop while they match */
j++;
k++;
if (k==(test+testLen)) return TRUE; /* got it */
}
}
return FALSE; /* no match */
}
/* Get the coordiates of the HyperCard card window */
GetCardRect(itsRect)
Rect *itsRect;
{
/* This version will work with SuperCard */
WindowPtr cardWindow;
Rect r;
Point thePt;
GetPort(&cardWindow);
r = (*cardWindow).portRect;
SetPt(&thePt,0,0);
LocalToGlobal(&thePt);
OffsetRect(&r,thePt.h,thePt.v);
*itsRect = r;
}
/* build a return result structure from a string */
ResultIs(paramPtr,theResult)
XCmdBlockPtr paramPtr;
char *theResult;
{
long len;
Handle resultHandle;
len = 1+strlen(theResult);
resultHandle = NewHandle(len);
BlockMove(theResult,*resultHandle,len);
paramPtr->returnValue = resultHandle;
}
/* show a string in an answer dialog - for debugging */
ShowString(paramPtr,text)
XCmdBlockPtr paramPtr;
char *text;
{
Str255 temp;
strcpy(temp,"answer \" ");
strcat(temp,text);
strcat(temp,"\"");
CtoPstr((char *)temp);
SendCardMessage(paramPtr,temp);
}
/* Change a HyperCard rectangle description into a QuickDraw rectangle */
GetHCRect(str,itsRect)
Str255 str;
Rect *itsRect;
{
Str255 it;
long corner;
GetHCItem(str,1,it);
CtoPstr((char *)it);
StringToNum(it,&corner);
itsRect->left = (int)corner;
GetHCItem(str,2,it);
CtoPstr((char *)it);
StringToNum(it,&corner);
itsRect->top = (int)corner;
GetHCItem(str,3,it);
CtoPstr((char *)it);
StringToNum(it,&corner);
itsRect->right = (int)corner;
GetHCItem(str,4,it);
CtoPstr((char *)it);
StringToNum(it,&corner);
itsRect->bottom = (int)corner;
}